package com.bysj.servlet;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bysj.entity.Bbs;
import com.bysj.fenye.pagevo.BbsPageVO;
import com.bysj.fenye.pagevo.UserPageVO;
import com.bysj.service.BbsService;
import com.bysj.service.impl.BbsServiceImpl;

public class BBSServlet extends HttpServlet {
	private BbsService bs=new BbsServiceImpl();
	private BbsPageVO pagevo=new BbsPageVO(10);
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String m=request.getParameter("m");
		String method=request.getParameter("method");
		if("pre".equals(method)){
			this.pagevo.setPrevious();
		}else if("next".equals(method)){
			this.pagevo.setNext();
		}else if("last".equals(method)){
			this.pagevo.setLast();
		}else if("index".equals(method)){
			String ind=request.getParameter("ind");
			this.pagevo.setIndex(Integer.parseInt(ind.trim()));
		}else{
			this.pagevo.setFirst();
		}
		if("AllBBS".equals(m)){
			request.getSession().setAttribute("Blist", pagevo);
			request.getRequestDispatcher("../bbs/allbbs.jsp").forward(request, response);
		}else if("DelBBS".equals(m)){
			Integer id=Integer.parseInt(request.getParameter("id"));
			Bbs b=new Bbs();
			b.setId(id);
			bs.delBBS(b);
			request.getSession().setAttribute("Blist", pagevo);
			request.getRequestDispatcher("../bbs/allbbs.jsp").forward(request, response);
			
		}
	}

}
